<!DOCTYPE html>
<html>
	<head th:include="/common/head :: head">
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit|ie-comp|ie-stand">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
		<meta http-equiv="Cache-Control" content="no-siteapp" />
	</head>
<body>
	<div class="x-body">
		<form class="layui-form" lay-filter="add_form">
			<div class="layui-form-item">
				<label for="chanceName" class="layui-form-label">机会名称:
				</label>
				<div class="layui-input-inline">
					<input type="text" id="chanceName" name="chanceName" lay-verify="chanceName" 
						 autocomplete="off" class="layui-input" >
				</div>
			</div>
			<div class="layui-form-item">
				<label for="type" class="layui-form-label">机会类型:
				</label>
				<div class="layui-input-inline">
					<select id="type" name="type">
						<option value="1">官网流量</option>
						<option value="2">转介绍</option>
						<option value="3">客户来访</option>
						<option value="4">媒体进线</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label for="content" class="layui-form-label">机会内容:
				</label>
				<div class="layui-input-block">
                  <textarea  id="content" name="content" autocomplete="off" class="layui-textarea" lay-verify="content"></textarea>
                </div>
			</div>
			<div class="layui-form-item">
				<label for="remarks" class="layui-form-label">备注信息:
				</label>
				<div class="layui-input-block">
                  <textarea  id="remarks" name="remarks" autocomplete="off" class="layui-textarea"></textarea>
                </div>
			</div>
			<div class="layui-form-item">
				<label for="L_repass" class="layui-form-label"> </label>
				<button class="layui-btn" lay-filter="add_form" lay-submit="">保存</button>
				<button class="layui-btn" onclick="black()">返回</button>
			</div>
		</form>
	</div>
</body>
</html>
<script>
	$(function(){
		//初始化
		initAddForm();
	})
	var _this = {};
	var addFormData={};
	//初始化（赋值）
	function initAddForm(){
		layui.use(['form','layer'],function(){
			$=layui.jquery;
			var form = layui.form,
			layer = layui.layer;
			//自定义验证
			form.verify({
				chanceName:function(value){
					if(value=="" ||value==null){
						return "机会名称不能为空";
					}
				},
				content:function(value){
					if(value=="" ||value==null){
						return "机会内容不能为空";
					}
				}
			})
			//监听提交
			form.on("submit(add_form)",function(data){
				console.log(data.field);
				addFormData = data.field;
				addChance();
				return false;
			})
		})
	}
	//提交添加操作
	function addChance(){
		$.ajax({
			url:"/chance/doAddChance",
			type:"post",
			data:{
				"chanceName":addFormData.chanceName,
				"type":addFormData.type,
				"content":addFormData.content,
				"remarks":addFormData.remarks
			},
			success:function(result){
				if(result.status==0){
					layer.msg(result.msg,function(){
						//关闭弹出层
						var index = parent.layer.getFrameIndex(window.name);
						parent.layer.close(index);
					})
				}else{
					layer.msg(result.msg);
				}
			}
		})
	}
	//返回
	function black(){
		var index = parent.layer.getFrameIndex(window.name);
		parent.layer.close(index);
	}
	
</script>
